<?php
class souhunavWidget extends Widget {

	public function render(){
		session_start();
		set_include_path(dirname(dirname(__FILE__)) . '/extensions/souhu/');
		require_once('oauth/SohuOAuth.php');
		require_once('config.php');
		/* 如果access token不存在，则重定向到connect.php去申请access token*/
		if (empty($_SESSION['access_token']) || empty($_SESSION['access_token']['oauth_token']) || empty($_SESSION['access_token']['oauth_token_secret'])) {
			$url = $this->create_url('authorize/souhu');
			$this->show_message('用户授权新浪微博，即将转入授权页面',$url,1 );
		
		}

		/*从 session 中获取access token*/
		$access_token = $_SESSION['access_token'];

		/* 使用token创建SohuOauth对象*/
		$oauth = new SohuOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);

		/*使用open api*/
		$url = 'http://api.t.sohu.com/users/show.json';
		$content = $oauth->get($url);
		$content = (array)$content;
		$this->assign('data' , $content);
		$this->display();
		// print_r($content);
	}
}